<?php
namespace App\Models\Api;

use App\Models\Api\Base;
use Cache;

class HeSijiaoText extends Base
{
    protected $table = 'he_sijiao_text';

    /**
     * 获取所有合轴词条
     */
    public function getHeSijiaoText()
    {
        $data = false;

        if (intval($this->cache_on) >= 1 && Cache::has('he_sijiao_text')) {
            $data = Cache::get('he_sijiao_text');
        }

        if ($data === false) {
            try
            {
                $data = $this
                    ->where('status',1)
                    ->selectOrFail();
                $data = json_decode(json_encode($data, true), true);
            } catch (\Exception $e) {
                $data = [];
            }

            if (intval($this->cache_on) >= 1) {
                 $temp = [];
                foreach ($data as $d) $temp[$d['planet']] = $d;
                $data = $temp;

                Cache::set('he_sijiao_text', $data, 86400 * 7);
            }
        }

        return $data;
    }

}
